﻿Public Class PosicionArista
    Inherits Posicion
    Private o As OrientacionArista
    Public Enum OrientacionArista
        Norte
        Noroeste
        Noreste
        Este
        Sureste
        Suroeste
        Oeste
        Sur
    End Enum

    Public Sub New(ByVal p As Posicion, ByVal o As OrientacionArista)
        MyBase.New(p)
        Me.o = o
    End Sub

    Public Sub New()
        MyBase.New()
        o = OrientacionArista.Este
    End Sub
    Public Sub New(ByVal pa As PosicionArista)
        MyBase.New(pa)
        o = pOrientacion

    End Sub
    Public Sub New(ByVal s As String)
        MyBase.New(s)
        o = s.Substring(s.IndexOf(":") + 1, s.Length)
    End Sub



    Public Sub normaliza()
        Select Case (o)
            Case OrientacionArista.Este
                pX = pX + 1
                o = OrientacionArista.Noroeste
            Case OrientacionArista.Noreste
                py = py + 1
                o = OrientacionArista.Noreste
            Case OrientacionArista.Noroeste
                pX = pX + 1
                py = py + 1
                o = OrientacionArista.Este
        End Select
    End Sub

    Public Function sinonimos(ByVal rpa As PosicionArista()) As PosicionArista()
        If rpa.Equals(Nothing) Then
            rpa(2) = New PosicionArista()
        End If
        For i As Integer = 0 To rpa.Length
            If rpa.Equals(Nothing) Then
                rpa(i) = New PosicionArista()
            End If
        Next i
        normaliza()
        Dim o1 As PosicionArista = rpa(0)
        Select Case o
            Case OrientacionArista.Este
                pX = pX + 1
                py = py - 1
                o = OrientacionArista.Oeste
            Case OrientacionArista.Noreste
                py = py - 1
                o = OrientacionArista.Suroeste
            Case OrientacionArista.Noroeste
                pX = pX - 1

                o = OrientacionArista.Sureste
        End Select
        Return rpa
    End Function

    Public Property pOrientacion() As OrientacionArista
        Get
            Return o
        End Get
        Set(ByVal value As OrientacionArista)
            o = value
        End Set
    End Property

    Public Overrides Function toString() As String
        Dim s As String = MyBase.toString
        Return s & ":" & o
    End Function

    Public Overrides Function equals(ByVal o As Object) As Boolean
        Dim p As PosicionArista = CType(o, PosicionArista)
        Return p.pX.Equals(Me.pX) And p.py.Equals(Me.py) And p.pOrientacion.Equals(Me.pOrientacion)
    End Function
End Class
